﻿/**
 * ...
 * @author	Kliment
 * @version	1.1.3
 */
class kliment.data.Directory {
	private var _list:Array;
	
	public function Directory() {
		_list = new Array();
	}
	
	public function push(word:Object, value:Object):Boolean {
		if (getValue(word))
			return false;
		_list.push( { word:word,  value:value } );
		return true;
	}
	
	public function add(word:Object, value:Object):Boolean {
		return push(word, value);
	}
	
	public function remove(word:Object):Boolean {
		var index:Number = _getItemIndex(word);
		if (index >= 0) {
			_list.splice(index, 1);
			return true;
		}
		return false;
	}
	
	public function getValue(word:Object):Object {
		var index:Number = _getItemIndex(word);
		if (index >= 0) 
			return _list[index].value;
		return null;
	}
	
	private function _getItemIndex(word:Object):Number {
		var i:Number = length;
		while (i--) 
			if (_list[i].word == word)
				return i;
		return -1;
	}
	
	public function get length():Number { return _list.length }
}